package com.team.ai.service;

import com.team.ai.entity.ResultEntity;
import com.team.ai.mapper.CarouselMapper;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class CarouselService {
    private static final Logger logger= LoggerFactory.getLogger(CarouselService.class);//日志getLogger需要传入的类名
    @Resource
    CarouselMapper carouselMapper;
    public String insert(String img,int bookid){
        try{
            return ResultEntity.success(carouselMapper.insert(img, bookid)) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public String delete(int id){
        try{
            return ResultEntity.success(carouselMapper.delete(id)) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public String update(String img,int bookid,int id){
        try{
            return ResultEntity.success(carouselMapper.update(img, bookid, id)) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public String selectList(){
        try{
            return ResultEntity.success(carouselMapper.selectList()) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
    public String selectDetail(int id){
        try{
            return ResultEntity.success(carouselMapper.selectDetail(id)) ;
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return  ResultEntity.fail(-10005);
        }
    }
}
